package com.framework.design;

public class TestSingleton {

	  private String name;
	    public String getName() {
	        return name;
	    }
	    public void setName(String name) {
	        this.name = name;
	    } 
	    //该类只能有一个实例
	    private TestSingleton(){}    //私有无参构造方法
	    //该类必须自行创建
	    
	    private static TestSingleton testSingleton =null;
	    //这个类必须自动向整个系统提供这个实例对象
	    public static TestSingleton getTestSingleton(){
	        if(testSingleton==null){
	        	testSingleton=new TestSingleton();
	        }
	        return testSingleton;
	    }
	    public void getInfo(){
	        System.out.println("output message "+name);
	    }
	    
	    
	    public static void main(String[] args) {
			// TODO Auto-generated method stub
	    	TestSingleton testSingleton = TestSingleton.getTestSingleton();
	    	testSingleton.setName("A123");
	    	System.out.println(testSingleton.getName());
	    	testSingleton.setName("B1234");
	    	
	    	
		}

}
